package com.nku.mason.scm.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nku.mason.scm.service.AccountService;
import com.nku.mason.scm.vo.Account;

@Controller
@RequestMapping("/account")
public class AccountAction {
	
	@Resource
	private AccountService accountService;
	
//	@RequestMapping(value="/insert")
//	public String insert(Account account){
//		System.out.println("---action.account:"+account);
//		accountService.insert(account);
//		return "main";
//	}
	@RequestMapping("/login")
	public String loggin(Account account,HttpServletRequest request,HttpSession session){
		System.out.println("---action.account:"+account);
		List<Account> existUsers = accountService.findAcc(account);
		if ( existUsers.size() > 0 ) {
			session.setAttribute("exsitUser", existUsers.get(0));
			return "main";
		} else {
			request.setAttribute("msg", "用户名或密码错误!");
			return "forward:/login.jsp";
		}
	}
	
	@RequestMapping("/doAjax")
	@ResponseBody//如果返回json格式，需要这个注解，这里用来测试环境
	public Object doAjax(Account account){
		System.out.println("---doAjax.supplier:"+account);
		account.setAccPass("789");
		return account;
	}
}
